/**
 * Copyright (C) 2014-2019 by Wen Yu.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * <p>
 * Any modifications to this file must keep this entire header intact.
 */

package com.symaster.common.pixy.image;

import java.util.HashMap;
import java.util.Map;

/**
 * Image types supported by ImageReader and ImageWriter.
 *
 * @author Wen Yu, yuwen_66@yahoo.com
 * @version 1.0 10/09/2012
 */
public enum ImageType {

    GIF("Gif") {
        @Override
        public String getExtension() {
            return "gif";
        }
    },

    PNG("Png") {
        @Override
        public String getExtension() {
            return "png";
        }
    },

    JPG("Jpeg") {
        @Override
        public String getExtension() {
            return "jpg";
        }
    },

    JPG2000("Jpeg2000") {
        @Override
        public String getExtension() {
            return "jp2";
        }
    },

    BMP("Bitmap") {
        @Override
        public String getExtension() {
            return "bmp";
        }
    },

    TGA("Targa") {
        @Override
        public String getExtension() {
            return "tga";
        }
    },

    TIFF("Tiff") {
        @Override
        public String getExtension() {
            return "tif";
        }
    },

    PCX("Pcx") {
        @Override
        public String getExtension() {
            return "pcx";
        }
    },

    UNKNOWN("Unknown") {
        @Override
        public String getExtension() {
            return null;
        }
    };

    private static final Map<String, ImageType> stringMap = new HashMap<>();

    static {
        for (ImageType type : values())
            stringMap.put(type.toString(), type);
    }

    private final String name;

    ImageType(String name) {
        this.name = name;
    }

    public static ImageType fromString(String name) {
        return stringMap.get(name);
    }

    public abstract String getExtension();

    @Override
    public String toString() {
        return name;
    }
}
